package com.ruoyi.strategy.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.dto.StrategyWithTypeDto;
import com.ruoyi.vo.StrategyWithTypeVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.strategy.domain.Strategy;
import com.ruoyi.strategy.service.IStrategyService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * strategyController
 *
 * @author sywc
 * @date 2025-01-09
 */
@RestController
@RequestMapping("/strategy")
public class StrategyController extends BaseController
{
    @Autowired
    private IStrategyService strategyService;

    /**
     * 查询strategy列表
     */
    @GetMapping("/list")
    public TableDataInfo list(Strategy strategy)
    {
        startPage();
        return getDataTable(strategyService.selectStrategyList(strategy));
    }

    /**
     * 导出strategy列表
     */

    @PostMapping("/export")
    public void export(HttpServletResponse response, Strategy strategy)
    {
        List<StrategyWithTypeVo> list = strategyService.selectStrategyList(strategy);
        ExcelUtil<StrategyWithTypeVo> util = new ExcelUtil<StrategyWithTypeVo>(StrategyWithTypeVo.class);
        util.exportExcel(response, list, "strategy数据");
    }

    /**
     * 获取strategy详细信息
     */
    @GetMapping(value = "/selectOne/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return success(strategyService.selectStrategyById(id));
    }

    /**
     * 新增strategy
     */
    @PostMapping("/add")
    public AjaxResult add(@RequestBody Strategy strategy)
    {
        return toAjax(strategyService.insertStrategy(strategy));
    }

    /**
     * 修改strategy
     */

 /*   @PutMapping("/update")
    public AjaxResult edit(@RequestBody StrategyWithTypeDto swtDto)
    {
        return toAjax(strategyService.updateStrategy(swtDto));
    }*/

    @PutMapping("/update")
    public AjaxResult edit(@RequestBody Strategy strategy)
    {
        return toAjax(strategyService.updateStrategy(strategy));
    }


    /**
     * 删除strategy
     */
	@DeleteMapping("/deleteMore/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(strategyService.deleteStrategyByIds(ids));
    }
}
